$(document).ready(function(){
    $("#nav_home_menu .menu_home a").hover(
        function () {
            SubMenu.hideAll();
            
            var menuId = $(this).attr("id");
            if(menuId === "home"){
                $("#home_sub_menu").css("display", "none");
                $("#VBPQ").removeClass("navHover");
                $("#TinXNK").removeClass("navHover");
                return;
            }
            else{
                $("#home_sub_menu").css("display", "block");
                $("#VBPQ").removeClass("navHover");
                $("#TinXNK").removeClass("navHover");
                $("#KTXNK").removeClass("navHover");
                $("#NVGN").removeClass("navHover");
                $("#HOIDAP").removeClass("navHover");
                $("#TTHQ").removeClass("navHover");
                $("#NVLQ").removeClass("navHover");
                $("#RAOVAT").removeClass("navHover");

                if (menuId === "TinXNK") {
                    $("#TinXNK").addClass("navHover");                    
                    $("#sub_tinxnk").css("display", "block");
                }
                else if(menuId === "VBPQ"){
                    $("#VBPQ").addClass("navHover");                    
                    $("#sub_vbpq").css("display", "block");
                }
                else if(menuId === "KTXNK"){
                    $("#KTXNK").addClass("navHover");                    
                    $("#sub_ktxnk").css("display", "block");   
                }
                else if(menuId === "NVGN"){
                    $("#NVGN").addClass("navHover");                    
                    $("#sub_nvgn").css("display", "block"); 
                }
                else if(menuId === "HOIDAP"){
                    $("#HOIDAP").addClass("navHover");                    
                    $("#sub_hoidap").css("display", "block"); 
                }
                else if(menuId === "TTHQ"){
                    $("#TTHQ").addClass("navHover");                    
                    $("#sub_tthq").css("display", "block"); 
                }
                else if(menuId === "NVLQ"){
                    $("#NVLQ").addClass("navHover");         
                    $("#home_sub_menu").css("display", "none");
                }
                else if(menuId === "RAOVAT"){
                    $("#RAOVAT").addClass("navHover");         
                    $("#home_sub_menu").css("display", "none");
                }
                else{
                    return;
                }
            }
        }
    );
    
    $("#home_sub_menu").hover(
        function(){
            $("#home_sub_menu").css("display", "block");
        },
        function(){
            $("#home_sub_menu").css("display", "none");
            SubMenu.removeActive();
        }
    );
    
    $("#page_header").hover(function(){
        $("#home_sub_menu").css("display", "none");
        SubMenu.removeActive();
    });
    
});

SubMenu = {
    removeActive : function(){
        $("#nav_home_menu a").each(function(){
            if($(this).attr("class") === "navHover"){
                $(this).removeClass("navHover");
            }
        });
    },
    hideAll : function(){
        $("#home_sub_menu").children("div").each(function(){
            $(this).css("display", "none");
        });
    },
    sendPost : function(url, params){
        if(url == "van-ban-phap-quy"){
            var arrParam = params.split("|");
            var callUrl = "/van-ban-phap-quy/tim-kiem";
            $("#formPost").attr("action", callUrl);
            for(var i=0; i<arrParam.length; i++){
                var value = arrParam[i].split(":");
                var hidId = value[0];
                var hidVal = value[1];
                var html = "<input type='hidden' name='" + hidId + "' value='" + hidVal + "' />";
                $("#formPost").append(html);
            }
            $("#formPost").submit();
        }
        else if(url == "hoi-dap"){
            var arrParam = params.split("|");
            var callUrl = "/hoi-dap/tim-kiem";
            $("#formPost").attr("action", callUrl);
            for(var i=0; i<arrParam.length; i++){
                var value = arrParam[i].split(":");
                var hidId = value[0];
                var hidVal = value[1];
                var html = "<input type='hidden' name='" + hidId + "' value='" + hidVal + "' />";
                $("#formPost").append(html);
            }
            $("#formPost").submit();
        }
    }
};